// This file is a part of ChaosDB.
// Copyright (C) 2012 ChaoJianPeng
// email:chaojianpeng@gmail.com
//
// ChaosDB is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// ChaosDB is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

/*
 * hashmap.h
 *
 *  Created on: 2012-3-4
 *      Author: chao
 */

#ifndef HASHMAP_H_
#define HASHMAP_H_

#define HASH_MAP_OK 0
#define HASH_MAP_ERR 1

#include <uthash.h>

typedef struct Entry {
	char* key;
	void* value;
	Entry* lruLeft;
	Entry* lruRight;
	UT_hash_handle hh;

} Entry;

Entry* entryCreat(char* key, void* value);
void entryDel(Entry* entry);
void entryRelease(Entry* entry);

typedef struct HashMap {
	Entry* ht;
} HashMap;

HashMap* hmCreat();
int hmSize(HashMap* hm);
Entry* hmHead(HashMap* hm);
Entry* hmAdd(HashMap* hm, char* key, void* value, int len);
Entry* hmSet(HashMap* hm, char* key, void* value, int len);
Entry* hmGet(HashMap* hm, char* key);
Entry* hmDel(HashMap* hm, char* key);
void hmClear(HashMap* hm);
Entry* hmReplace(HashMap* hm, char* key, void* value, int len);

#endif /* HASHMAP_H_ */
